package com.leonardo.persistenceme.model;

import java.util.Vector;

import com.leonardo.persistenceme.exceptions.DatabaseOperationException;
import com.leonardo.persistenceme.model.persistancehandlers.PersistenceHandler;

public interface PersistenceManager {

	Integer numPersistedEntities();
	
	/*Returns the Entity Key*/
	Integer persist(Entity entity) throws DatabaseOperationException;
	Integer persist(Entity entity, PersistenceHandler handler) throws DatabaseOperationException;
	Integer persist(Entity entity, String model) throws DatabaseOperationException;
	
	/*Offer and persist if the key doesn't exist. Key must be not null*/
	boolean offer(Entity entity) throws DatabaseOperationException;
	boolean offer(Entity entity, PersistenceHandler handler) throws DatabaseOperationException;
	boolean offer(Entity entity, String model) throws DatabaseOperationException;
	
	/*Update an entity that has the given key*/
	void update(Entity entity) throws DatabaseOperationException;
	void update(Entity entity, PersistenceHandler handler) throws DatabaseOperationException;
	void update(Entity entity, String model) throws DatabaseOperationException;
	
	Entity getByKey(Integer key) throws DatabaseOperationException;
	Entity getByKey(Integer key, PersistenceHandler handler) throws DatabaseOperationException;
	Entity getByKey(Integer key, String model) throws DatabaseOperationException;
	
	Vector listAll() throws DatabaseOperationException;
	Vector listAll(PersistenceHandler handler) throws DatabaseOperationException;
	Vector listAll(String model) throws DatabaseOperationException;
	
	
	Vector list(Filter filter) throws DatabaseOperationException;
	Vector list(Filter filter, PersistenceHandler handler) throws DatabaseOperationException;
	Vector list(Filter filter, String model) throws DatabaseOperationException;
	
	Vector list(Class clazz) throws DatabaseOperationException;
	Vector list(Class clazz, PersistenceHandler handler) throws DatabaseOperationException;
	Vector list(Class clazz, String model) throws DatabaseOperationException;
	
	void delete(Integer key) throws DatabaseOperationException;
	
	void deleteAll(Filter filter) throws DatabaseOperationException;
	void deleteAll(Filter filter, PersistenceHandler handler) throws DatabaseOperationException;
	void deleteAll(Filter filter, String model) throws DatabaseOperationException;
	
	void deleteAll(Class clazz) throws DatabaseOperationException;
	void deleteAll(Class clazz, PersistenceHandler handler) throws DatabaseOperationException;
	void deleteAll(Class clazz, String model) throws DatabaseOperationException;
	
	void clearDB() throws DatabaseOperationException;
}
